package vip.xiaonuo.smzq.modular.lifecycle.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import vip.xiaonuo.smzq.modular.lifecycle.base.KqfwCoordinates;
import vip.xiaonuo.smzq.modular.lifecycle.constant.LifeCycleConstant;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 三维坐标VO
 */
@Data
public class ThreeWeftCoorVO {
    @ApiModelProperty("wgs84面坐标")
    private String coor84;
    @ApiModelProperty("该坐标的地上地下标高信息")
    private List<ThreeDHeightVO> threeDHeightVOS=CollUtil.newArrayList();

    @ApiModelProperty("最大高度")
    private Double maxH;

    @ApiModelProperty("最小高度")
    private Double minH;

    public void initMaxMinH(List<KqfwCoordinates> coors){
        if(CollUtil.size(coors)>0){
            List<KqfwCoordinates> heightCoors = coors.stream().filter(ele-> StrUtil.equals("*",ele.getInflectionPoint())).collect(Collectors.toList());
            if(CollUtil.size(heightCoors)>0){
                KqfwCoordinates heightCoor = CollUtil.getFirst(heightCoors);

                if(ObjectUtil.isNotEmpty(heightCoor.getX())){
                    this.setMaxH(Convert.toDouble(heightCoor.getX()));
//                    result.set(LifeCycleConstant.heightMaxKey,heightCoor.getX());
                }
                if(ObjectUtil.isNotEmpty(heightCoor.getY())){
//                    result.set(LifeCycleConstant.heightMinKey,heightCoor.getY());
                    this.setMinH(Convert.toDouble(heightCoor.getY()));
                }

            }
        }
    }

    public void initThreeDHVOS(List<KqfwCoordinates> coors){
        initMaxMinH(coors);

        Double maxHeight = this.maxH;
        Double minHeight = this.minH;
//        分四种情况，都有值，都没值，最大有最小没有，最小有，最大没有
//        都有值
        if(ObjectUtil.isNotEmpty(maxHeight) && ObjectUtil.isNotEmpty(minHeight)){
//           最大有最小没有
//            地上地下都有
            if(maxHeight>0 && minHeight<0){
                this.threeDHeightVOS.add(getThreeDHeightVO(maxHeight,maxHeight));
                this.threeDHeightVOS.add(getThreeDHeightVO(minHeight,Math.abs(minHeight)));
//                都是在地上
            }else if(maxHeight>0 && minHeight>0){
                this.threeDHeightVOS.add(getThreeDHeightVO(maxHeight,Math.abs(maxHeight - minHeight)));
//                只有地下
            }else if(maxHeight<0 && minHeight<0){
                this.threeDHeightVOS.add(getThreeDHeightVO(minHeight,Math.abs(maxHeight - minHeight)));
            }else if(maxHeight ==0 && minHeight<0){
                this.threeDHeightVOS.add(getThreeDHeightVO(minHeight,Math.abs(minHeight)));

            }else if(maxHeight>0 && minHeight==0){
                this.threeDHeightVOS.add(getThreeDHeightVO(maxHeight,maxHeight));
            }else if(maxHeight == 0 && minHeight==0){
                this.threeDHeightVOS.add(getThreeDHeightVO(1d,1d));
            }else if(maxHeight<0 && minHeight>0){
                this.threeDHeightVOS.add(getThreeDHeightVO(minHeight,minHeight));
                this.threeDHeightVOS.add(getThreeDHeightVO(maxHeight,Math.abs(maxHeight)));
            }
        }else if(ObjectUtil.isNotEmpty(maxHeight) && ObjectUtil.isEmpty(minHeight)){

            this.threeDHeightVOS.add(getThreeDHeightVO(maxHeight,Math.abs(maxHeight)));

//            最小有，最大没有
        }else if(ObjectUtil.isEmpty(maxHeight) && ObjectUtil.isNotEmpty(minHeight)){
            this.threeDHeightVOS.add(getThreeDHeightVO(minHeight,Math.abs(minHeight)));
        }
    }

    /**
     * 得到3d高度信息
     * @param elevation 标高
     * @param graphHeight 图形高度
     * @return
     */
    private ThreeDHeightVO getThreeDHeightVO(Double elevation,Double graphHeight){
        ThreeDHeightVO result = new ThreeDHeightVO();
        result.setElevation(elevation);
        result.setGraphHeight(graphHeight);
        return result;
    }
}
